#ifndef CPP_APPLICATION_H
#define CPP_APPLICATION_H

#include <Global.h>
#include <Context.h>
#include <utils/Timer.h>

//@brief 主应用
//@author cvte
//@description 每个应用的入口类
class Application : public Context {
   public:
    friend class MainWindow;

    enum class ApplicationType {
        ACTIVITY,
        SERVICE
    };
    Application();
    virtual ~Application();
    virtual void onCreate();
    int start();
    //@method 设置识别物理按键长按的时间，默认3000ms，超时会回调onKeyLongPress
    void setKeyLongPressTimeMs(int timeMs);
    //@method 获取识别物理按键长按的时间
    int getKeyLongPressTimeMs();

   protected:
    void onTerminate();
    void onLowMemory();

    void setApplicationType(ApplicationType type) {
        this->mType = type;
    }
    bool dispatchKeyEvent(KeyEvent& keyEvent);

   private:
    ApplicationType mType = ApplicationType::ACTIVITY;
    KeyEvent mLastKeyEvent;
    long mKeyLongPressTimerTaskId = -1;
    Timer mKeyLongPressTimer;
    int mKeyLongPressTimeMs = 3000; //物理按键默认长按事件为3000ms
    bool mShouldSkipKeyUpOnce = false; //是否忽略一次KeyUp的处理，目前需要在长按后忽略KeyUp事件
};

#endif /* CPP_APPLICATION_H */
